﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DbHelp;

namespace IotherRis
{
    public partial class Fr_add_Node : DevExpress.XtraEditors.XtraForm
    {
        public Fr_add_Node()
        {
            InitializeComponent();
        }
        string mIid = "";
        string mPid = "";
        uDataSetC mUds = null;
        public Fr_add_Node(string pIid, string pPid)
        {
            InitializeComponent();
            mIid = pIid;
            mPid = pPid;
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            if (lue_pid.EditValue == null)
            {

                MessageBox.Show("请选择父节点编码");
                return;
            }

            try
            {
                mUds.SetItem(1, "BODYPART", txt_bodypart.Text);
                mUds.SetItem(1, "MODALITY", txt_modality.Text);
                mUds.SetItem(1, "TEMPLATE_NAME", txt_name.Text);
                mUds.SetItem(1, "IPID", lue_pid.EditValue.ToString());
                //mUds.SetItem(1, "TEMPLATE_DESC", txt_desc.Text);
                //mUds.SetItem(1, "TEMPLATE_DIAG", txt_diagonew.Text);
                mUds.Update(AccessHelper.mReportDb);
                MessageBox.Show("保存成功");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存失败");
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //加载该节点的父节点同级节点
            string mSql_pid = "select * from  PI_REPORTTEMPLATE  where  ipid ="+mPid;

            uDataSetC mUds_pid = new uDataSetC(mSql_pid, AccessHelper.mReportDb);

            lue_pid.Properties.DataSource = mUds_pid.Tables[0];
            lue_pid.Properties.DisplayMember = "TEMPLATE_NAME";
            lue_pid.Properties.ValueMember = "IID";

            string mSql = "select * from pi_reporttemplate where iid=-1";
            mUds = new uDataSetC(mSql, AccessHelper.mReportDb);
            if (mUds.RowCount() >= 1)
            {
                txt_bodypart.Text = mUds.GetItemString(1, "BODYPART");
                txt_modality.Text = mUds.GetItemString(1, "MODALITY");
                txt_name.Text = mUds.GetItemString(1, "TEMPLATE_NAME");

            }
            else
            {
                mUds.InsertRow();
                txt_bodypart.Text = "";
                txt_modality.Text = "";
                txt_name.Text = "";
            }
            string mSql_load_modlatys = @"select * from pi_baseinfo where cparamtype='设备类型' and ipid<>0";
            uDataSetC mDs_modlaitys = new uDataSetC(mSql_load_modlatys, AccessHelper.mReportDb);
            txt_modality.Properties.Items.Clear();
            

            for (int i = 1; i <= mDs_modlaitys.RowCount(); i++)
            {
                txt_modality.Properties.Items.Add(mDs_modlaitys.GetItemString(i, "CPARAMCODE"));
            }
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
